package com.xiao.kafka.producer.controller;

import com.xiao.common.utils.JsonUtils;
import com.xiao.kafka.producer.constant.KafkaProducerTopic;
import com.xiao.kafka.producer.message.KafkaProducer;
import com.xiao.kafka.producer.vo.TestMessageVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * @Description kafka消息生产者控制器
 * @Auther: 笑笑是一个码农
 * @Date: 16:52 2021/1/6
 */
@RestController
public class KafkaProducerController {

    @Resource
    private KafkaProducer kafkaProducer;

    /**
     * kafka消息生产者示例接口
     * @param testMessageVo
     */
    @PostMapping(value = "/v1/kafka-producer/message")
    public void sendMessage(@RequestBody TestMessageVo testMessageVo){
        kafkaProducer.send(KafkaProducerTopic.TEST_TOPIC, JsonUtils.serialize(testMessageVo));
    }
}
